package com.jqsoft.launcher.activity.childCareManagement;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.jqsoft.launcher.activity.WebViewActivity;
import com.jqsoft.launcher.activity.bean.LittleChildBean;
import com.jqsoft.launcher.activity.bean.UserLoginInfo;
import com.jqsoft.launcher.activity.gairui.Spo2Example;
import com.jqsoft.launcher.activity.personnelInformationList.PersonnelInformationActivity;
import com.jqsoft.launcher.common.BphsConstants;
import com.jqsoft.launcher.common.BphsURL;
import com.jqsoft.launcher.util.CommonUtil;
import com.jqsoft.launcher.util.DateTools;
import com.jqsoft.launcher.util.FileService;
import com.jqsoft.launcher.util.Log;
import com.jqsoft.launcher.util.MessageTools;
import com.jqsoft.launcher.util.WebServiceUtils;
import com.jqsoft.launcher.util.XmlUtil;

import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class XSEFollowUpRecordActivity3 extends WebViewActivity implements
		View.OnClickListener {

	LittleChildBean personInfo;
	UserLoginInfo info = UserLoginInfo.getInstances();
	String jsonstr = null;
	private int updateIndex = -1;
	private String sPersonID1;
	private String sNo1;// 档案编号
	private String sname1;// 姓名
	private String sCardNo1;// 证件号码

	private String tiwen = "0";
	private String mailv = "0";
	private String huxipinlv = "0";
	private String sAreaCode,sAreaName,gChildrenInfoRegisterKey;

	@Override
	protected void initGui() {
		super.initGui();
		webView.loadUrl("file:///android_asset/xse_followup_record.html");
		webView.addJavascriptInterface(new JSObject(), "contact");
	}

	@Override
	protected void initAction() {
		setGoBack();
	}

	@Override
	protected void initData() {
		setTitle("新生儿家庭访视记录表");
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		if (bundle != null) {
			personInfo = (LittleChildBean) bundle.get("MPGuanLi_PersonInfo");
			jsonstr = bundle.getString("Tjdata");
			sPersonID1 = bundle.getString("sPersonID");
			sNo1 = bundle.getString("sNo");
			sname1 = bundle.getString("sname");
			sCardNo1 = bundle.getString("sCardNo");
			updateIndex = bundle.getInt("chakan");
		}
	}

	@Override
	public void onClick(View v) {
	}

	private final class JSObject {
		// 初始化页面
		@JavascriptInterface
		public void getHtml() {
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					try {
						Map<String, String> map = new HashMap<String, String>();
						map.put("Gender", "Sexs"); // 性别
						map.put("sGestationName", "Gestation"); // 母亲妊娠期患病情况
						map.put("sBornConditionName", "BornCondition"); // 出生情况
						map.put("Youwu", "Youwu"); // 新生儿窒息、是否有畸型、呕吐、颈部包块、转诊建议
						map.put("sApgarName", "Apgar"); // Apgar评分情况
						map.put("sHearScreeningName", "HearScreening"); // 新生儿听力筛查
						map.put("sIllnessScreeningName", "IllnessScreening"); // 新生儿疾病筛查
						map.put("sFeedName", "Feed"); // 喂养方式
						map.put("YESorNo", "Suckneed"); // 按需哺乳
						map.put("iSuckTimesName", "SuckTimes"); // 母乳喂养次数
						map.put("sStoolName", "Stool"); // 大便
						map.put("Child_Complexion", "FacialExpression"); // 面色
						map.put("NewBornVisiting_sJaundiceName", "Jaundice"); // 黄疸部位
						map.put("NewBornVisiting_sHalogenBeforeName",
								"HalogenBefore"); // 前囟说明
						map.put("ErrorState", "ErrorState"); // 眼外观、四肢活动度、耳外观、鼻、口腔、肛门、心肺听诊、外生殖器、腹部触诊、脊柱
						map.put("FristPrenatalCheck_Skin", "Skin"); // 皮肤
						map.put("FristPrenatalCheck_UmbilicalCord",
								"UmbilicalCord"); // 脐带
						map.put("NewBornVisiting_sGuideName", "Guide"); // 指导

						JSONObject jsonObj = CommonUtil.getAllDictionary(map);
						if (personInfo != null) {
							jsonObj.put("sName", personInfo.getsPersonName()); // 页面回显姓名
							jsonObj.put("sNo", personInfo.getsNo()); // 页面回显档案号
							jsonObj.put("Sex", personInfo.getsSexCode());// 页面回显性别
							SimpleDateFormat sdf = new SimpleDateFormat(
									"yyyy/MM/dd");
							String birthdaystr = personInfo.getdBirthday()
									.replace("-", "/");
							Date birthday = sdf.parse(personInfo.getdBirthday()
									.replace("-", "/"));
							jsonObj.put("Birthday", DateTools
									.getFormatStringByDF_YYYY_MM_DD(birthday));// 页面回显出生日期
							jsonObj.put("CardNo", personInfo.getsCardNo());// 页面回显证件号码
							jsonObj.put("RegisterNo",
									personInfo.getsRegisterNo());// 页面回显保健手册编码
							if (StringUtils.isNotEmpty(personInfo
									.getdRegisterDate().replace("-", "/"))) {// 页面回显建册日期
								Date registerDate = sdf.parse(personInfo
										.getdRegisterDate().replace("-", "/"));
								jsonObj.put(
										"RegisterDate",
										DateTools
												.getFormatStringByDF_YYYY_MM_DD(registerDate));
							} else {
								jsonObj.put("RegisterDate", "");
							}
						}

						jsonObj.put("dVisitingDate", DateTools
								.getFormatStringByDF_YYYY_MM_DD(new Date()));// 本次随访日期
						jsonObj.put("dNextVisitingDate", DateTools
								.getFormatStringByDF_YYYY_MM_DD(DateTools
										.getNextMonthByDate(new Date(), 3)));// 下次随访日期
						jsonObj.put("sNextVisitingPlace",
								info.getsOrganizationName());// 随访单位
						jsonObj.put("DoctorList", info.getJsonArrayDoctors());// 回显随访医生列表
						jsonObj.put("sVisitingDoctor", info.getsUserName());// 随访医生
						String json = jsonObj.toString();
						JSONObject jsonObj2 = null;
						if (jsonstr != null) {
							jsonstr = jsonstr.replace("\n", "");
							jsonstr = jsonstr.replace("\\n", "");
							// jsonstr = jsonstr.replace("\r", "");
							jsonObj2 = new JSONObject(jsonstr);
							sAreaCode = jsonObj2.getString("sAreaCode");
							sAreaName = jsonObj2.getString("sAreaName");
							gChildrenInfoRegisterKey=jsonObj2.getString("gChildrenInfoRegisterKey");
						}
						// 初始化
						webView.loadUrl("javascript:showHtml('" + json + "','"
								+ jsonstr + "')");
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
		}

		// 保存操作
		@SuppressWarnings("unused")
		@JavascriptInterface
		public void save(String uploadType, String sName, String sNo,
				String sSex, String dBornDate, String sIDCardNo,
				String sAddress, String sRegisterNo, String dRegisterDate,
				String sFatherName, String sFatherJob, String sFatherPhone,
				String sFatherBirthday, String sMotherName, String sMotherJob,
				String sMotherPhone, String sMotherBirthday,
				String iWeeksGestation, String sAccoucheDept,
				String sGestationCode, String sGestationOther,
				String sBornConditionCode, String sBornOtherCondition,
				String sStuffinessCode, String sApgarCode,
				String sDeformityCode, String sDeformityexplain,
				String sHearScreeningCode, String sIllnessScreeningCode,
				String sIllnessScreeningOther, String sHeartDiseaseCode,
				String sSuspectedContent, String dBornWeight,
				String dNowWeight, String dHeight, String sFeedCode,
				String dSuckneedCode, String sSuckTimesCode, String sVomitCode,
				String sStoolCode, String iStoolTimes, String dBodyTemperature,
				String iPulseRate, String iBreathingRate,
				String sFacialExpressionCode, String sFacialExpressionOther,
				String sJaundiceCode, String dHalogenBefore1,
				String dHalogenBefore2, String sHalogenBeforeCode,
				String sHalogenBeforeother, String sEyesOutwardCode,
				String sEyesOutwardOther, String sLegsActivityCode,
				String sLegsActivityOther, String sEarsOutwardCode,
				String sEarsOutwardOther, String sNeckMassCode,
				String sNeckMassOther, String sNoseCode, String sNoseOther,
				String sSkinCode, String sSkinOther, String sMouseCode,
				String sMouseOther, String sHepaticPortCode,
				String sHepaticPortOther, String sHeartLungCode,
				String sHeartLungOther, String sGenitalsCode,
				String sGenitalsOther, String sStomachCode,
				String sStomachOther, String sBackBoneCode,
				String sBackBoneOther, String sUmbilicalCordCode,
				String sUmbilicalCordOther, String sReferralAdivseCode,
				String sReferralReason, String sAgencyDepartments,
				String sGuideCode, String dVisitingDate,
				String dNextVisitingDate, String sNextVisitingPlace,
				String sVisitingDoctor, String iWeatherHealthEducation,
				String sWeatherHealthEducationContent,
				String BaoJianZhidaoContent, String BaoJianZhidaoContentCode) {
			try {
				String gHypertensionVisitingKey = CommonUtil.getUUID();
				final JSONObject jsonVistingInfo = new JSONObject();

				jsonVistingInfo.put("tiwen", tiwen);
				jsonVistingInfo.put("mailv", mailv);
				jsonVistingInfo.put("huxipinlv", huxipinlv);

				// 页面回显
				jsonVistingInfo.put("sName", sName);
				jsonVistingInfo.put("sSex", sSex);
				jsonVistingInfo.put("dBornDate", dBornDate);
				jsonVistingInfo.put("sIDCardNo", sIDCardNo);
				jsonVistingInfo.put("sAddress", sAddress);
				jsonVistingInfo.put("sRegisterNo", sRegisterNo);
				jsonVistingInfo.put("dRegisterDate", dRegisterDate);

				jsonVistingInfo.put("gKey", gHypertensionVisitingKey);
				if (personInfo != null) {
					jsonVistingInfo.put("sPersonID", personInfo.getsPersonID());
					jsonVistingInfo.put("sNo", personInfo.getsNo());
				} else {
					jsonVistingInfo.put("sPersonID", sPersonID1);
					jsonVistingInfo.put("sNo", sNo1);
				}
				jsonVistingInfo.put("gChildrenInfoRegisterKey",gChildrenInfoRegisterKey);
				jsonVistingInfo.put("dVisitingYear",dVisitingDate.substring(0, 4));
				jsonVistingInfo.put("iVisitingTimes", 0);// ?
				jsonVistingInfo.put("sFatherName", "");// sFatherName
				jsonVistingInfo.put("sFatherJob", "");// sFatherJob
				jsonVistingInfo.put("sFatherPhone", sFatherPhone);
				jsonVistingInfo.put("sFatherBirthday", "");// ?sFatherBirthday
				jsonVistingInfo.put("sMotherName", "");// sMotherName
				jsonVistingInfo.put("sMotherJob", "");// sMotherJob
				jsonVistingInfo.put("sMotherPhone", "");// sMotherPhone
				jsonVistingInfo.put("sMotherBirthday", "");// ?sMotherBirthday
				jsonVistingInfo.put("iWeeksGestation", iWeeksGestation);// ?
				jsonVistingInfo.put("sGestationName", "");
				jsonVistingInfo.put("sGestationCode", sGestationCode);
				jsonVistingInfo.put("sGestationOther", sGestationOther);
				jsonVistingInfo.put("sAccoucheDept", sAccoucheDept);
				jsonVistingInfo.put("sBornConditionName", "");
				jsonVistingInfo.put("sBornConditionCode", sBornConditionCode);
				jsonVistingInfo.put("sBornOtherCondition", sBornOtherCondition);
				jsonVistingInfo.put("sStuffinessName", "");
				jsonVistingInfo.put("sStuffinessCode", sStuffinessCode);
				jsonVistingInfo.put("sApgarName", "");
				jsonVistingInfo.put("sApgarCode", sApgarCode);
				jsonVistingInfo.put("sDeformityName", "");
				jsonVistingInfo.put("sDeformityCode", sDeformityCode);
				jsonVistingInfo.put("sDeformityexplain", sDeformityexplain);
				jsonVistingInfo.put("sHearScreeningName", "");
				jsonVistingInfo.put("sHearScreeningCode", sHearScreeningCode);
				jsonVistingInfo.put("sSuspectedContent", sSuspectedContent);
				jsonVistingInfo.put("sIllnessScreeningName", "");
				jsonVistingInfo.put("sIllnessScreeningCode",
						sIllnessScreeningCode);
				jsonVistingInfo.put("sIllnessScreeningOther",
						sIllnessScreeningOther);
				jsonVistingInfo.put("dBornWeight", dBornWeight);
				jsonVistingInfo.put("dNowWeight", dNowWeight);
				jsonVistingInfo.put("dHeight", dHeight);
				jsonVistingInfo.put("sFeedName", "");
				jsonVistingInfo.put("sFeedCode", sFeedCode);
				jsonVistingInfo.put("dBodyTemperature", dBodyTemperature);
				jsonVistingInfo.put("dSuckneedName", "");
				jsonVistingInfo.put("dSuckneedCode", dSuckneedCode);
				jsonVistingInfo.put("sSuckTimesName", "");
				jsonVistingInfo.put("sSuckTimesCode", sSuckTimesCode);
				jsonVistingInfo.put("iPulseRate", iPulseRate);
				jsonVistingInfo.put("iBreathingRate", iBreathingRate);
				jsonVistingInfo.put("sVomitName", "");
				jsonVistingInfo.put("sVomitCode", sVomitCode);
				jsonVistingInfo.put("sStoolName", "");
				jsonVistingInfo.put("sStoolCode", sStoolCode);
				jsonVistingInfo.put("iStoolTimes", iStoolTimes);
				jsonVistingInfo.put("sFacialExpressionName", "");
				jsonVistingInfo.put("sFacialExpressionCode",
						sFacialExpressionCode);
				jsonVistingInfo.put("sFacialExpressionOther",
						sFacialExpressionOther);
				jsonVistingInfo.put("sJaundiceName", "");
				jsonVistingInfo.put("sJaundiceCode", sJaundiceCode);
				jsonVistingInfo.put("dHalogenBefore1", dHalogenBefore1);
				jsonVistingInfo.put("dHalogenBefore2", dHalogenBefore2);
				jsonVistingInfo.put("sHalogenBeforeName", "");
				jsonVistingInfo.put("sHalogenBeforeCode", sHalogenBeforeCode);
				jsonVistingInfo.put("sHalogenBeforeother", sHalogenBeforeother);
				jsonVistingInfo.put("sEyesOutwardName", "");
				jsonVistingInfo.put("sEyesOutwardCode", sEyesOutwardCode);
				jsonVistingInfo.put("sEyesOutwardOther", sEyesOutwardOther);
				jsonVistingInfo.put("sEarsOutwardName", "");
				jsonVistingInfo.put("sEarsOutwardCode", sEarsOutwardCode);
				jsonVistingInfo.put("sEarsOutwardOther", sEarsOutwardOther);
				jsonVistingInfo.put("sLegsActivityName", "");
				jsonVistingInfo.put("sLegsActivityCode", sLegsActivityCode);
				jsonVistingInfo.put("sLegsActivityOther", sLegsActivityOther);
				jsonVistingInfo.put("sNeckMassName", "");
				jsonVistingInfo.put("sNeckMassCode", sNeckMassCode);
				jsonVistingInfo.put("sNeckMassOther", sNeckMassOther);
				jsonVistingInfo.put("sNoseName", "");
				jsonVistingInfo.put("sNoseCode", sNoseCode);
				jsonVistingInfo.put("sNoseOther", sNoseOther);
				jsonVistingInfo.put("sSkinName", "");
				jsonVistingInfo.put("sSkinCode", sSkinCode);
				jsonVistingInfo.put("sMouseOther", sMouseOther);
				jsonVistingInfo.put("sSkinOther", sSkinOther);
				jsonVistingInfo.put("sMouseName", "");
				jsonVistingInfo.put("sMouseCode", sMouseCode);
				jsonVistingInfo.put("sHepaticPortName", "");
				jsonVistingInfo.put("sHepaticPortCode", sHepaticPortCode);
				jsonVistingInfo.put("sHepaticPortOther", sHepaticPortOther);
				jsonVistingInfo.put("sHeartLungName", "");
				jsonVistingInfo.put("sHeartLungCode", sHeartLungCode);
				jsonVistingInfo.put("sHeartLungOther", sHeartLungOther);
				jsonVistingInfo.put("sGenitalsName", "");
				jsonVistingInfo.put("sGenitalsCode", sGenitalsCode);
				jsonVistingInfo.put("sGenitalsOther", sGenitalsOther);
				jsonVistingInfo.put("sStomachName", "");
				jsonVistingInfo.put("sStomachCode", sStomachCode);
				jsonVistingInfo.put("sStomachOther", sStomachOther);
				jsonVistingInfo.put("sBackBoneName", "");
				jsonVistingInfo.put("sBackBoneCode", sBackBoneCode);
				jsonVistingInfo.put("sBackBoneOther", sBackBoneOther);
				jsonVistingInfo.put("sUmbilicalCordName", "");
				jsonVistingInfo.put("sUmbilicalCordCode", sUmbilicalCordCode);
				jsonVistingInfo.put("sUmbilicalCordOther", sUmbilicalCordOther);
				jsonVistingInfo.put("sReferralAdivseName", "");
				jsonVistingInfo.put("sReferralAdivseCode", sReferralAdivseCode);
				jsonVistingInfo.put("sReferralReason", sReferralReason);
				jsonVistingInfo.put("sAgencyDepartments", sAgencyDepartments);
				jsonVistingInfo.put("sGuideName", "");
				jsonVistingInfo.put("sGuideCode", sGuideCode);
				jsonVistingInfo.put("dVisitingDate", dVisitingDate);
				jsonVistingInfo.put("dNextVisitingDate", dNextVisitingDate);
				jsonVistingInfo.put("sNextVisitingPlace", sNextVisitingPlace);
				jsonVistingInfo.put("sVisitingDoctor", sVisitingDoctor);
				jsonVistingInfo.put("sAreaCode", sAreaCode);
				jsonVistingInfo.put("sAreaName", sAreaName);
				jsonVistingInfo.put("sAddUser", info.getsLoginName());
				jsonVistingInfo.put("dAddTime", DateTools
						.getFormatStringByDF_YYYY_MM_DD_HH_MM_SS(new Date()));
				jsonVistingInfo.put("sUpdateUser", "");
				jsonVistingInfo.put("dUpdateTime", "");
				jsonVistingInfo.put("sDeleteUser", "");
				jsonVistingInfo.put("dDeleteTime", "");
				jsonVistingInfo.put("sInputDeptName",
						info.getsOrganizationName());
				jsonVistingInfo.put("sInputDeptCode",
						info.getsOrganizationKey());
				jsonVistingInfo.put("iState", 1);
				jsonVistingInfo.put("iWeatherHealthEducation",
						iWeatherHealthEducation);
				jsonVistingInfo.put("sWeatherHealthEducationContent",
						sWeatherHealthEducationContent);
				jsonVistingInfo.put("sJingbuName", "");
				jsonVistingInfo.put("sJingbuCode", "");// ?
				jsonVistingInfo.put("sBiName", "");
				jsonVistingInfo.put("sBiCode", "");// ?
				jsonVistingInfo.put("skouqiangName", "");
				jsonVistingInfo.put("skouqiangCode", "");// ?
				jsonVistingInfo.put("BaoJianZhidaoContent",
						BaoJianZhidaoContent);
				jsonVistingInfo.put("BaoJianZhidaoContentCode",
						BaoJianZhidaoContentCode);
				jsonVistingInfo.put("sHeartDiseaseName", "");
				jsonVistingInfo.put("sHeartDiseaseCode", sHeartDiseaseCode);
				jsonVistingInfo.put("sVisitingDoctorCode", "");
				jsonVistingInfo.put("sVisitingPlaceCode", "");
				Log.i("benny", jsonVistingInfo.toString());
				if ("2".equals(uploadType)) {
					XSEFollowUpRecordActivity3.this
							.runOnUiThread(new Runnable() {
								@Override
								public void run() {
									try {
										boolean issuccess = false;
										if (updateIndex >= 0
												&& personInfo == null) {

											issuccess = new FileService(act)
													.updateFromRom(
															updateIndex,
															sPersonID1,
															sNo1,
															sname1,
															sCardNo1,
															"儿童保健随访",
															jsonVistingInfo
																	.toString(),
															"append.txt");
										} else {
											issuccess = new FileService(act).saveToRom(
													personInfo.getsPersonID(),
													personInfo.getsNo(),
													personInfo.getsPersonName(),
													personInfo.getsCardNo(),
													"儿童保健随访",
													jsonVistingInfo.toString(),
													"append.txt");
										}
										if (issuccess) {
											MessageTools
													.showDialogOk(ctx,
															"保存成功！本次随访数据保存在本机，请到“离线设置”-“上传随访信息”中上传或者修改数据！");
										} else {
											Toast.makeText(
													XSEFollowUpRecordActivity3.this,
													"保存失败！", Toast.LENGTH_SHORT)
													.show();
										}
									} catch (Exception e) {
										Toast.makeText(
												XSEFollowUpRecordActivity3.this,
												"保存失败！", Toast.LENGTH_SHORT)
												.show();
										e.printStackTrace();
									}
								}
							});
				} else if (BphsConstants.isNetAvailable
						&& "1".equals(uploadType)) {
					XSEFollowUpRecordActivity3.this
							.runOnUiThread(new Runnable() {
								@Override
								public void run() {
									// 创建了对话框的构造器
									Builder builder = new Builder(
											XSEFollowUpRecordActivity3.this);
									builder.setTitle("温馨提示");
									builder.setMessage("确定将本次随访数据提交至服务器吗？注意：提交后本条数据无法在平板上再次修改！");
									builder.setPositiveButton("确定",
											new OnClickListener() {
												public void onClick(
														DialogInterface dialog,
														int which) {
													try {
														// String methodName =
														// "AddNewBornVisiting";
														// String serviceURL =
														// "http://60.171.146.122:9098/WebService/Andrews/ChildrenInfoWebService.asmx";
														String serviceURL = BphsURL
																.getCommonPath("AddNewBorn_URL");
														String methodName = BphsURL
																.getCommonPath("AddNewBorn_METHOD");
														String result = WebServiceUtils
																.requestByParams(
																		methodName,
																		jsonVistingInfo
																				.toString(),
																		serviceURL);
														if (StringUtils
																.isNotBlank(result)) {
															Log.i("result",
																	result);
															JSONObject json = new JSONObject(
																	result);
															String sResult = json
																	.getString("sSuccess");
															if (sResult
																	.equals("1")) {
																Toast.makeText(
																		XSEFollowUpRecordActivity3.this,
																		"保存完成！",
																		Toast.LENGTH_SHORT)
																		.show();
															} else {
																Toast.makeText(
																		XSEFollowUpRecordActivity3.this,
																		"保存失败！",
																		Toast.LENGTH_SHORT)
																		.show();
															}
														} else {
															Toast.makeText(
																	XSEFollowUpRecordActivity3.this,
																	"远程服务器故障！",
																	Toast.LENGTH_SHORT)
																	.show();
														}
													} catch (Exception e) {
														e.printStackTrace();
													}
												}
											});
									builder.setNegativeButton("取消",
											new OnClickListener() {

												public void onClick(
														DialogInterface dialog,
														int which) {
													Toast.makeText(
															XSEFollowUpRecordActivity3.this,
															"保存失败！",
															Toast.LENGTH_SHORT)
															.show();
												}
											});
									AlertDialog dialog = builder.create();
									dialog.setCancelable(false);
									dialog.setCanceledOnTouchOutside(false);
									dialog.show();

								}

							});
				} else {
					Toast.makeText(XSEFollowUpRecordActivity3.this,
							"离线状态只能保存随访信息！", Toast.LENGTH_LONG).show();
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		// 调用蓝牙接口返回xml数据
		@JavascriptInterface
		public void getXML(String type) {
			switch (BphsConstants.deviceBranchType) {
			case 0:
				Intent intent = new Intent();
				// 通讯接口
				intent.setComponent(new ComponentName(
						"com.example.uray.bluetooth.comm.app",
						"com.example.uray.bluetooth.comm.app.CommActivity"));
				// 参数配置接口
				// intent.setComponent(new
				// ComponentName("com.example.uray.bluetooth.comm.app",
				// "com.example.uray.bluetooth.comm.app.ConfigActivity"));
				intent.setAction(Intent.ACTION_VIEW);
				if (type.equals("1")) {
					startActivityForResult(intent, 1); // 获取体温值
				} else if (type.equals("2")) {
					startActivityForResult(intent, 2); // 获取脉率值
				} else {
					startActivityForResult(intent, 3); // 获取呼吸率值
				}
				break;
			case 1:
				if ("1".equals(type)) {
					MessageTools.showDialogOk(ctx, "当前功能还未开通，请手动输入！"); // 获取体温值
				} else if ("2".equals(type)) {
					Intent iSpo2 = new Intent(XSEFollowUpRecordActivity3.this,
							Spo2Example.class);
					startActivityForResult(iSpo2, 4); // 获取脉率值

				} else {
					MessageTools.showDialogOk(ctx, "当前功能还未开通，请手动输入！"); // 获取呼吸率值
				}
				break;
			default:
				break;
			}
		}

		// 导入母亲信息 ,sex为性别代码
		@JavascriptInterface
		public void importMother() {
			if (!BphsConstants.isNetAvailable) {
				Toast.makeText(XSEFollowUpRecordActivity3.this, "离线状态下，请手动输入！",
						Toast.LENGTH_SHORT).show();
				return;
			}
			Intent intent = new Intent(XSEFollowUpRecordActivity3.this,
					PersonnelInformationActivity.class);
			Bundle bundle = new Bundle();
			bundle.putString("sex", "2");
			intent.putExtras(bundle);
			startActivityForResult(intent, 200);
		}

		// 导入父亲信息 ,sex为性别代码
		@JavascriptInterface
		public void importFather() {
			if (!BphsConstants.isNetAvailable) {
				Toast.makeText(XSEFollowUpRecordActivity3.this, "离线状态下，请手动输入！",
						Toast.LENGTH_SHORT).show();
				return;
			}
			Intent intent = new Intent(XSEFollowUpRecordActivity3.this,
					PersonnelInformationActivity.class);
			Bundle bundle = new Bundle();
			bundle.putString("sex", "1");
			intent.putExtras(bundle);
			startActivityForResult(intent, 100);
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// 回显父亲信息
		if (requestCode == 100 && resultCode == RESULT_OK) {
			JSONObject jsonObject = new JSONObject();
			try {
				jsonObject.put("name", data.getStringExtra("name"));// 回显母亲姓名
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
				Date birthday = sdf.parse(data.getStringExtra("dBirthday")
						.replace("-", "/"));
				jsonObject.put("dBirthday",
						DateTools.getFormatStringByDF_YYYY_MM_DD(birthday));// 页面回显母亲出生日期
				jsonObject.put("sPhone", data.getStringExtra("sPhone"));// 回显母亲联系电话
				webView.loadUrl("javascript:showFather('"
						+ jsonObject.toString() + "')");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		// 回显母亲信息
		if (requestCode == 200 && resultCode == RESULT_OK) {
			JSONObject jsonObject = new JSONObject();
			try {
				jsonObject.put("name", data.getStringExtra("name"));// 回显母亲姓名
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
				Date birthday = sdf.parse(data.getStringExtra("dBirthday")
						.replace("-", "/"));
				jsonObject.put("dBirthday",
						DateTools.getFormatStringByDF_YYYY_MM_DD(birthday));// 页面回显母亲出生日期
				jsonObject.put("sPhone", data.getStringExtra("sPhone"));// 回显母亲联系电话
				webView.loadUrl("javascript:showMother('"
						+ jsonObject.toString() + "')");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		// 解析蓝牙接口返回的XML格式的字符串
		if (requestCode == 1 && resultCode == RESULT_OK) {
			// 获取体温值
			String sb = data.getStringExtra("return");
			// StringBuffer sb = new StringBuffer();
			// try {
			// InputStream in = getResources().getAssets().open("c.xml");
			// byte[] b = new byte[4096];
			// int n;
			// while ((n = in.read(b))!= -1){
			// sb.append(new String(b,0,n));
			// }
			// } catch (IOException e) {
			// e.printStackTrace();
			// }
			String jsonStr = XmlUtil.parseXml(sb);
			// MessageTools.showDialogOk(ctx, "返回结果", sb);
			// Toast.makeText(ctx, a, 1).show();
			tiwen = "1";
			webView.loadUrl("javascript:showXML('" + jsonStr + "')");
		}
		if (requestCode == 2 && resultCode == RESULT_OK) {
			// 获取脉率值
			String sb = data.getStringExtra("return");
			// StringBuffer sb = new StringBuffer();
			// try {
			// InputStream in = getResources().getAssets().open("c.xml");
			// byte[] b = new byte[4096];
			// int n;
			// while ((n = in.read(b))!= -1){
			// sb.append(new String(b,0,n));
			// }
			// } catch (IOException e) {
			// e.printStackTrace();
			// }
			String jsonStr = XmlUtil.parseXml(sb);
			// MessageTools.showDialogOk(ctx, "返回结果", sb);
			// Toast.makeText(ctx, a, 1).show();
			JSONObject json;
			try {
				json = new JSONObject(jsonStr);
				final String cPulseRate = json.getString("cPulseRate") == "null" ? ""
						: json.getString("cPulseRate");
				mailv = "1";
				webView.loadUrl("javascript:showXML2('" + cPulseRate + "')");
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		if (requestCode == 3 && resultCode == RESULT_OK) {
			// 获取呼吸率值
			String sb = data.getStringExtra("return");
			// StringBuffer sb = new StringBuffer();
			// try {
			// InputStream in = getResources().getAssets().open("c.xml");
			// byte[] b = new byte[4096];
			// int n;
			// while ((n = in.read(b))!= -1){
			// sb.append(new String(b,0,n));
			// }
			// } catch (IOException e) {
			// e.printStackTrace();
			// }
			String jsonStr = XmlUtil.parseXml(sb);
			// MessageTools.showDialogOk(ctx, "返回结果", sb);
			// Toast.makeText(ctx, a, 1).show();
			huxipinlv = "1";
			webView.loadUrl("javascript:showXML3('" + jsonStr + "')");
		}

		if (requestCode == 4 && data != null) {
			String cPulseRate = data.getStringExtra("cPulseRate");
			mailv = "1";
			webView.loadUrl("javascript:showXML2('" + cPulseRate + "')");
		}
	}
}
